'''
Created on 12.09.2009

@author: ankstoo
'''

import Pyro.core
from pygs.logger import logger

class RemoteObject(Pyro.core.ObjBase):
    '''
    '''
    
    def __init__(self, obj):
        Pyro.core.ObjBase.__init__(self)
        self.delegateTo(obj)

class RemoteServer(object):
    '''
    '''
    
    def __init__(self, obj):
        object.__init__(self)
        self.remoteObject = RemoteObject(obj)  
        
    def run(self, serverHost=None, serverPort=None, serverName=None):
        Pyro.core.initServer()
        daemon = Pyro.core.Daemon(host=serverHost, port=serverPort)
        logger.log("The remoting server daemon runs on port: %s" % daemon.port)

        uri = daemon.connect(self.remoteObject, serverName)
        logger.log("The remoting server uri is: %s" % uri)

        daemon.requestLoop()
        
def connectServer(uri):
    return Pyro.core.getProxyForURI(uri)